package com.xuecheng.freemarker.controller;

import com.xuecheng.freemarker.model.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.util.*;

/**
 * @author: gongfy
 * @create: 2020/7/9 15:55
 * @Description:
 */

@RequestMapping(value = "/freemarker")
@Controller
@Slf4j
public class FreeMarkerController {

    @Autowired
    private RestTemplate restTemplate;
    /**
    * @Author: gongfy
    * @Param: 
    * @Return: 静态化页面模板
    * @Date: 2020/7/11 10:36
    * @Description: 1.通过远程调用manage_cms动态获取轮播图数据 2.返回给模板页面   todo 问题：返回路径的templates是默认的路径吗？ 返回的是ftl格式而不是html页面
    **/
    @RequestMapping(value = "/banner")
    public String test2(Map<String,Object> map) {
        String dataUrl = "http://localhost:31001/cms/config/getModel/5a791725dd573c3574ee333f";
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(dataUrl, Map.class);
        Map body = forEntity.getBody();
        map.putAll(body);
        log.info("返回:"+body);
        return "index_banner";
    }

    
    /**
    * @Author: gongfy
    * @Param: 
    * @Return: 
    * @Date: 2020/8/5 9:31
    * @Description: 课程预览模板测试
    **/
    @RequestMapping(value = "/course")
    public String course(Map<String,Object> map) {
        String dataUrl = "http://localhost:31200/course/courseview/4028e581617f945f01617f9dabc40000";
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(dataUrl, Map.class);
        Map body = forEntity.getBody();
        map.putAll(body);
        log.info("返回:"+body);
        return "course";
    }
}
